package com.piz.dao.product;

import java.util.List;

import javax.persistence.criteria.Expression;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;


import com.piz.dao.common.PizHiberImpl;
import com.piz.dao.common.UnexpectedDBException;
import com.piz.model.ItemCategory;

/**
 * @author prameetk.sharma
 *
 */
public class ProductCategoryDao extends PizHiberImpl<ItemCategory>{
	
	/**
	 * @return
	 */
	public List<ItemCategory> getAllProductTypes()
	{
		try {
			String hqlQuery = "from ItemCategory";
			return (List<ItemCategory>) executeHQL(hqlQuery);
		} catch (Exception e) {
			throw new UnexpectedDBException("DBException in fetching item categories.",e);
		}
		
	}
	
	/**
	 * @param catName
	 * @return
	 */
	public List<?> fetchCatByName(String catName) {
		try {
			String hqlQuery = "from ItemCategory cat where cat.name='"+catName+"'";
			return (List<ItemCategory>) executeHQL(hqlQuery);
		} catch (Exception e) {
			throw new UnexpectedDBException("DBException in fetching item categories by name.",e);
		}
	}

	/**
	 * @param id
	 * @return
	 */
	public ItemCategory fetchCatById(Long id)
	{
		try {
			return search(ItemCategory.class, id);
		} catch (Exception e) {
			throw new UnexpectedDBException("DBException in searching item categories by id.",e);
		}
		
	}
}
